{extend name="base" /}
{block name="body"}
<div class="layui-card">
    <div class="layui-card-header">
        <div class="layui-btn-group">
            {if auth_url('crm/contract/add')}
            <a href="{:url('crm/contract/add')}" class="layui-btn ajax-detail">添加</a>
            {/if}
        </div>
    </div>

    <table id="tableList" lay-filter="tableList"></table>
    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        {if auth_url('crm/contract/edit')}
        <a href="{:url('crm/contract/edit')}?id={{d.id}}" class="layui-btn layui-btn-sm ajax-detail">修改</a>
        {/if}
        {if auth_url('crm/contract/del')}
        <a href="{:url('crm/contract/del')}?id={{d.id}}" class="layui-btn layui-btn-danger layui-btn-sm ajax-delete">删除</a>
        {/if}
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="customer">
        <a href="{:url('crm/customer/detail')}?id={{d.customer_id}}" class="layui-btn layui-btn-primary layui-btn-sm">{{d.customer.name}} {{d.customer.mobile}}</a>
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="type">
        {{# if(d.type == '0'){ }}
        <a class="layui-btn layui-btn-sm layui-btn-primary">系统记录</a>
        {{# }else if(d.type == '1'){ }}
        <a class="layui-btn layui-btn-normal layui-btn-sm">客服跟进</a>
        {{# } }}
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="user">
        <a href="{:url('index')}?user_id={{d.user_id}}" class="layui-btn layui-btn-primary layui-btn-sm">{{d.user.name}}</a>
    </script>
    <!-- 权限列 -->
    <script type="text/html" id="product">
        {{#  layui.each(d.get_product, function(index, item){ }}
        <a class="layui-btn layui-btn-primary layui-btn-sm">{{item}}</a>
        {{#  }); }}
    </script>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'dropdown'], function () {

        var table = layui.table;
        // 渲染回访表格
        var insTb = table.render({
            elem: '#tableList',
            url: "{:url('crm/contract/index_json')}",
            page: true,
            cellMinWidth: 100,
            limit:'15',
            limits:[15,30,50,100,200,500,1000],
            size:'lg',even:true,
            cols: [[
                {type:'numbers',title:'#'},
                {field: 'datetime', align: 'left', sort: true, title: '签单日期'},
                {templet: '#customer', align: 'left', sort: true, title: '客户',width:200},
                {field: 'contract_no', align: 'left', sort: true, title: '合同编号'},
                {field: 'start_time', align: 'left', sort: true, title: '起始日期'},
                {field: 'end_time', align: 'left', sort: true, title: '到期日期'},
                {field: 'price', align: 'left', sort: true, title: '合同金额'},
                {templet: '#product', align: 'left', sort: true, title: '产品',width: 250},
                {templet: '#user', align: 'left', sort: true, title: '操作用户',width: 120},
                {field: 'create_time', align: 'center', sort: true, title: '创建时间',width: 200},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', width: 160}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                  "code": res.code, //解析接口状态
                  "msg": res.msg, //解析提示文本
                  "count": res.data.total, //解析数据长度
                  "data": res.data.data //解析数据列表
                };
            }
        });

    });

</script>
{/block}